package com.zzrc.grape.controller;

import com.zzrc.grape.model.bank.ChangeBankStatusReq;
import com.zzrc.grape.model.bank.UserGidReq;
import com.zzrc.grape.service.BankService;
import com.zzrc.grape.util.BasePageData;
import com.zzrc.grape.util.WebResponseCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Date;

@Controller
@RequestMapping("/bank")
public class BankController {
    @Resource
    BankService bankService;
    @RequestMapping("goBankStatustIndex")
    public ModelAndView goBankStatustIndex() {
        ModelAndView modelView = new ModelAndView();
        modelView.setViewName("bank/bankStatusIndex");
        return modelView;
    }

    @RequestMapping("goBankInfoSelectIndex")
    public ModelAndView goBankInfoSelectIndex() {
        ModelAndView modelView = new ModelAndView();
        modelView.setViewName("bank/bankSelectIndex");
        return modelView;
    }

    @RequestMapping("changeBankStatus")
    @ResponseBody
    public BasePageData changeBankStatus(@RequestBody ChangeBankStatusReq changeBankStatusReq) {
        BasePageData basePageData = new BasePageData();
        System.out.println(changeBankStatusReq.toString());
        int result = bankService.changeBankStatus(changeBankStatusReq);

        if (result > 0) {
            basePageData.setCode(WebResponseCode.SUCCESS);
            basePageData.setMsg(WebResponseCode.SUCCESSINFO);
            basePageData.setCount(result);

        } else {
            basePageData.setCode(WebResponseCode.FAIL);
            basePageData.setMsg(WebResponseCode.FAILINFO);
        }
        basePageData.setData(new Date());
        return basePageData;
    }

    @RequestMapping("getBankCardList")
    @ResponseBody
    public BasePageData getBankCardList(@RequestBody UserGidReq userGidReq) {
        String userGid = userGidReq.getUserGid();
        return bankService.getBankCardList(userGid);
    }

    @RequestMapping("getBankAccountList")
    @ResponseBody
    public BasePageData getBankAccountList(@RequestBody UserGidReq userGidReq) {
        String userGid = userGidReq.getUserGid();
        return bankService.getBankAccountList(userGid);
    }

    @RequestMapping("getOperateBankCardList")
    @ResponseBody
    public BasePageData getOperateBankCardList(@RequestBody UserGidReq userGidReq) {
        String userGid = userGidReq.getUserGid();
        return bankService.getOperateBankCardList(userGid);
    }
}
